export default class CustomEvent {
  constructor() {
    // 收集事件的容器
    this.handlers = {}
  }
  // 订阅(添加事件)
  on(evname, handler) {
    if (!Array.isArray(this.handlers[evname])) {
      // 初始化事件函数栈
      this.handlers[evname] = []
    }
    this.handlers[evname].push(handler)
  }
  // 发布(触发事件)
  emit(evname, params) {
    for (let val of Object.keys(this.handlers)) {
      if (val == evname) {
        for (let val of this.handlers[evname]) {
          val(params)
        }
      }
    }
  }
}